<?php

namespace apiend\modules\shop\models;

use Yii;
use yii\data\ActiveDataProvider;
use common\models\shop\ShopProduct;
use common\models\shop\ShopGoods;

/**
 * This is the model class for table "{{%dynamic}}".
 *
 * @property int $id
 * @property string $user_id 用户ID
 * @property string $content
 * @property int $direction 动态类型：0主动动态，1被动动态
 * @property int $retweet_id 转发动态原始ID
 * @property int $status
 * @property string $created_at
 * @property string $updated_at
 * @property string $deleted_at
 */
class CartPackSearch extends \common\models\shop\ShopCart {

    /**
     * @inheritdoc
     */
    public function fields() {
        return [
            'id',
            'name' => function() {
                return $this->product ? $this->product->name : '';
            },
            'sku' => function() {
                return $this->goods ? $this->goods->name : '';
            },
            'price' => function() {
                return $this->goods ? floatval($this->goods->price) : 0;
            },
            'num',
            'thumb' => function() {
                return $this->goods ? $this->goods->thumb : '';
            },
            'checked' => function() {
                return $this->status == static::STATUS_CHECKED;
            },
            'status' => function() {
                if (!($this->goods && $this->product)) {
                    return false;
                }
                return $this->goods->status == ShopGoods::STATUS_ACTIVE && $this->product->status == ShopProduct::STATUS_ACTIVE;
            },
            'product_id',
            'goods_id',
            'express' => function() {
                if ($this->product) {
                    return $this->product->template_id;
                }
                return 0;
            },
        ];
    }

}
